package com.wealth.scsj.p_app.view.fragment;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.wealth.scsj.p_app.R;
import com.wealth.scsj.p_app.adapter.GetGoodsListAdapter;
import com.wealth.scsj.p_app.adapter.OrderIndexAdapter;
import com.wealth.scsj.p_app.bean.OrderIndexBean;
import com.wealth.scsj.p_app.utils.DialogUtils;
import com.wealth.scsj.p_app.utils.SkipUtils;

import java.util.ArrayList;
import java.util.List;

import es.dmoral.toasty.Toasty;

/**
 *  待取货
 */
public class GetFragment extends BaseFragment {

    private RecyclerView order_rv;
    private List<OrderIndexBean> orderIndexBeanList;
    private OrderIndexAdapter adapter;
    private GetGoodsListAdapter getGoodsListAdapter;
    private List goodsLists;
    private RecyclerView getGoodsListRv;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_get, null);
        initView(inflate,null);
        initData();
        return inflate;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        order_rv = view.findViewById(R.id.order_rv);
        order_rv.setLayoutManager(new LinearLayoutManager(getHoldingActivity()));
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        orderIndexBeanList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            orderIndexBeanList.add(new OrderIndexBean("fff", "fff", "fff", "fff", "fff", "fff", "fff", "fff"));
        }
        adapter = new OrderIndexAdapter(orderIndexBeanList);
        order_rv.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                view.findViewById(R.id.order_detail_tv).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        SkipUtils.toOrderDetail(getHoldingActivity());
                    }
                });

                view.findViewById(R.id.contact_tv).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toasty.info(getHoldingActivity(), "点击了").show();
                    }
                });
                view.findViewById(R.id.make_sure_tv).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //确认取货弹窗
                        showConfirmGetGoodsWiddow();
                    }
                });
            }
        });
    }

    private void showConfirmGetGoodsWiddow() {

        DialogUtils.getInstance()
                .with(getActivity())//上下文
                .setlayoutId(R.layout.confirm_get_goods_layout)//布局文件
                .setlayoutPosition(Gravity.CENTER)//位置
                .setlayoutAnimaType(1)//动画类型:0自下而上动画，1淡入淡出动画
                .setlayoutPading(100, 500, 100, 500)//与屏幕距离
                .setOnChildViewclickListener(new DialogUtils.ViewInterface() {
                    @Override
                    public void getChildView(View view, int layoutResId) {
                        //处理dialog内部控件的点击事件
                        //TextView callNoticeTv = view.findViewById(R.id.call_notice_tv);
                        getGoodsListRv= view.findViewById(R.id.goods_list_rv);
                        getGoodsListRv.setLayoutManager(new LinearLayoutManager(getActivity()));
                        getGoodsListRv.setNestedScrollingEnabled(false);
                        goodsLists= new ArrayList();
                        for (int i=0;i<2;i++){
                            goodsLists.add(i+"");
                        }
                        getGoodsListAdapter= new GetGoodsListAdapter(goodsLists,getActivity());
                        getGoodsListRv.setAdapter(getGoodsListAdapter);
                        //点击取消按钮
                        TextView cancelBtn= view.findViewById(R.id.order_detail_state_left_tv);
                        cancelBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                DialogUtils.dismiss();
                            }
                        });
                    }
                })
                .show();
    }

    @Override
    protected int getLayoutId() {
        return 0;
    }

}
